Linux系统集群架构线上项目配置实战(四)
写在前面
项目到目前为止,前面将所有应用工程的安装与配置已阐述完成,今天将要介绍的是数据库的安装、配置、主从同步等相关过程
至于数据库的安装与配置,在之前的文章中也介绍过很多种方法,一般数据库的几种安装方法如下:
1、yum安装
此种安装,一般用于内网对数据库要求不高的环境,如监控服务等
2、常规编译安装
5.5之前的版本可直接使用./configure make && make install 直接进行编译安装即可,但之后的版本需要引用第三方软件cmake,然后进行编译安装
3、rpm包安装
下载相应的rpm包进行安装
4、二进制安装
下载相应版本的二进制安装包,解压、初始化即可完成安装
对于哪种方法安装好,按实际生需求来
今天介绍的就是使用二进制安装包进行安装mysql
安装相关依赖库
yum install libao libao-devel -y
添加用户
groupadd mysql
useradd -g mysql mysql -s /sbin/nologin –M
下载软件
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
解压至目录
[root@mysql-m ~]# tar zxf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
[root@mysql-m ~]# ln -s /usr/local/mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql
[root@mysql-m mysql]# mkdir /data
[root@mysql-m mysql]#chown –R mysql.mysql /data
初始化数据库
[root@mysql-m ~]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
2017-09-23T09:14:16.724707Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-09-23T09:14:17.698204Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-09-23T09:14:17.888059Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-09-23T09:14:17.977944Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 93b7f20c-a03f-11e7-b91d-000c29d812ec.
2017-09-23T09:14:17.988894Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-09-23T09:14:17.995157Z 1 [Note] A temporary password is generated for root@localhost: csnbtzNIf0-6
拷贝启动文件
[root@mysql-m ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@mysql-m ~]# chmod +x /etc/init.d/mysqld
[root@mysql-m ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@mysql-m ~]# lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 1639 mysql 20u IPv6 15683 0t0 TCP *:mysql (LISTEN)
[root@mysql-m ~]# ln -s /data/mysql.sock /tmp/
默认登陆是通过/tmp/mysql.sock文件来连接mysql,可以在配置文件里指定路径也可以实现此种效果,否则登录就会报错
########以上配置另外的从库同上述操作###############
其实相关的配置之前的文章也有介绍过,但为了整个项目的完整性,在此再次介绍一遍整个操作过程
修改主从服务器的配置文件
[root@mysql-m ~]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql/
datadir = /data
socket = /data/mysql.sock
server-id = 1
log-bin = /data/mysql-bin
relay-log = /data/master.relay-bin
relay-log-info-file = /data/master.relay-log.info
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
replicate-ignore-db=mysql
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@mysql-s ~]# vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data
socket=/data/mysql.sock
49 30728 49 15091 0 0 1248 0 0:00:24 0:00:12 0:00:12 2981user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
server-id = 2
#log-bin = /data/mysql-bin
relay-log = /data/slave.relay-bin
relay-log-info-file = /data/slave.relay-log.info
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
配置文件注释就不过多介绍,可参考前面的文章
主库创建并授权同步的用户
mysql> grant replication slave on *.* to rep@'10.0.0.%' identified by'123456';
Query OK, 0 rows affected, 1 warning (0.04 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)
主从服务器重启服务,主库进行全备
将全备文件推送至从库
恢复从库
执行change master语句
[root@mysql-s ~]# mysql -uroot -p123456 </root/master.sql
[root@mysql-s ~]# mysql -uroot -p123456
mysql> change master to
-> master_host='10.0.0.11',
-> master_port=3306,
-> master_user='rep',
-> master_password='123456',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.04 sec)
mysql> start slave;
Query OK, 0 rows affected (0.02 sec)
查看同步状态
测试主从同步
主从同步整个过程配置完成,实际生产环境此种架构后面会扩展成读写分离,一主多从,双主多从等,看实际生产需求与个人技术点与学习成本,后续会介绍相关读写分离与高可用的架构实战,敬请期待!!!
redis安装非常简单
下载、解压至指定目录、启动即可完成
可参考前面的相关文章介绍
监控安装这里也不再赘述了,前面有大幅文章介绍安装与配置过程
写文不易,如有帮助扫码打赏民工哥